package com.rk.jarjuggler.gui;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import com.intellij.openapi.ui.Messages;

public class LibTypePanel extends JPanel {
    private JRadioButton moduleRadio;
    private boolean hasProjectLibWarningBeenShown;

    public LibTypePanel(){
        super(new FlowLayout());

        JLabel label = new JLabel("Add as a module or project level library?");
        add(label);
        moduleRadio = new JRadioButton("Module");
        JRadioButton projectRadio = new JRadioButton("Project");
        ButtonGroup bg = new ButtonGroup();
        bg.add(moduleRadio);
        bg.add(projectRadio);
        moduleRadio.setSelected(true);
        add(moduleRadio);
        add(projectRadio);

        projectRadio.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent actionEvent) {
                if (!hasProjectLibWarningBeenShown) {
                    hasProjectLibWarningBeenShown = true;
                    Messages.showInfoMessage(LibTypePanel.this, "(Currently only supported in IntelliJ 5) \n When adding at the project level, the library defaults as inactive for all modules.  You must manually go to Settings->Modules->Libraries afterwards to activate.", "Jar Juggler");
                }
            }
        });

    }

    public boolean isModuleLibSelected(){
        return moduleRadio.isSelected();
    }
}
